'use strict';

const getDishes = require('./get-dishes');
const addDish = require('./add-dish');
const updateDish = require('./update-dish');
const deleteDish = require('./delete-dish');
const batchOperate = require('./batch-operate');
const getStatistics = require('./get-statistics');
const getDishDetail = require('./get-dish-detail');

exports.main = async (event, context) => {
  const { action, data } = event;
  
  try {
    switch (action) {
      case 'get-dishes':
        return await getDishes.main(event, context);
      case 'add-dish':
        return await addDish.main(event, context);
      case 'update-dish':
        return await updateDish.main(event, context);
      case 'delete-dish':
        return await deleteDish.main(event, context);
      case 'batch-operate':
        return await batchOperate.main(event, context);
      case 'get-statistics':
        return await getStatistics.main(event, context);
      case 'get-dish-detail':
        return await getDishDetail.main(event, context);
      default:
        return {
          code: 400,
          message: '未知的操作类型',
          data: null
        };
    }
  } catch (error) {
    console.error('云函数执行错误:', error);
    return {
      code: 500,
      message: '服务器内部错误',
      data: null
    };
  }
};